package com.web.base.wechat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.blue.jdbc.JdbcDataSource;
import com.blue.jdbc.Page;
import com.web.base.wechat.exception.WechatAutoMessageException;
import com.web.base.wechat.dao.WechatAutoMessageDao;
import com.web.base.wechat.model.WechatAutoMessage;
import com.web.core.util.Const;

/**
 * 微信自动回复消息业务层
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月27日
 */
@Service
@Transactional
@JdbcDataSource(Const.DS_BASE)
public class WechatAutoMessageService
{
	@Autowired
	private WechatAutoMessageDao wechatAutoMessageDao;
	
	public WechatAutoMessageService()
	{
	}
	
	public WechatAutoMessage save(WechatAutoMessage wechatAutoMessage)
	{
		if (wechatAutoMessageDao.exist(wechatAutoMessage, "replyType", "code"))
			throw new WechatAutoMessageException("类型和代码已经存在：code=" + wechatAutoMessage.getCode());
			
		if (wechatAutoMessage.getId() == null)
		{
			wechatAutoMessageDao.save(wechatAutoMessage);
		}
		else
		{
			wechatAutoMessageDao.update(wechatAutoMessage);
		}
		WechatAutoMessage a = wechatAutoMessageDao.get(wechatAutoMessage.getId());
		return a;
	}
	
	public WechatAutoMessage get(Integer id)
	{
		WechatAutoMessage log = wechatAutoMessageDao.get(id);
		return log;
	}
	
	public Page<WechatAutoMessage> list(WechatAutoMessage wechatAutoMessage, Page<WechatAutoMessage> page)
	{
		page = wechatAutoMessageDao.list(wechatAutoMessage, page);
		return page;
	}
	
	public List<WechatAutoMessage> list(WechatAutoMessage message)
	{
		List<WechatAutoMessage> list = wechatAutoMessageDao.list(message);
		return list;
	}
	
	public void delete(WechatAutoMessage wechatAutoMessage)
	{
		wechatAutoMessageDao.delete(wechatAutoMessage);
	}
	
}
